#!/usr/bin/python
# -*- coding: utf-8 -*-

import gtk 
import webkit 
import webbrowser


class PageWindow:
    def __init__(self, link):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_decorated(False)
#        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_TOOLTIP)
        self.window.resize(700, 300)
        self.window.move((gtk.gdk.screen_width()/2)-(700/2), (gtk.gdk.screen_height())-(300)-56)
        self.vbox = gtk.VBox()
        self.hbox = gtk.HBox()

        button1 =gtk.Button()
        button1 = gtk.Button(stock=gtk.STOCK_CLOSE)
        button1.connect("clicked", self.destroy_every, None)
        button1.connect("clicked", lambda w: self.window.destroy())
        self.hbox.pack_start(button1, expand = False)
        self.link = link
        button2 =gtk.Button("Open In Browser")
        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON)
        button2.set_image(image)

        button2.connect("clicked", self.open_browser, None)
        self.hbox.pack_start(button2)

        self.vbox.pack_start(self.hbox, expand = False)



        self.hbox2 = gtk.HBox()

        self.vscale = gtk.VScale()
        self.hbox2.pack_start(self.vscale, expand = False)
        self.view = webkit.WebView()
        sw = gtk.ScrolledWindow()
        sw.set_border_width(5)
        sw.add(self.view)
        self.hbox2.pack_end(sw, expand = True)


        self.vbox.pack_end(self.hbox2)


        self.window.add(self.vbox)
        self.window.set_border_width(5)
        self.window.show_all() 
        self.view.open(link)
        self.view.set_zoom_level(1)

#    def main(self):
#        gtk.main()

    def open_browser(self, widget=None, data=None):
        webbrowser.open(self.link)

    def destroy_every(self, widget=None, data=None):
        self.view.destroy()
        del self.view
